home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / crystal / cvmotd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-12  |  1.9 KB  |  94 lines

  1. /* cvmotd.c
  2.  *************************************************************************/
  3.  
  4. #include    <stdio.h>
  5. #include    <time.h>
  6. #include    <filehdr.h>
  7. #include    <ldfcn.h>
  8. #include    "cvmisc.h"
  9.  
  10. #define    MLEN    500
  11.  
  12. extern long time();
  13. extern char *crypt();
  14. extern char *malloc();
  15. extern void free();
  16. extern char *word1;
  17.  
  18. static char msg[MLEN] = "\nUNIX PC Crystal version 1.7\n";
  19. static char salt[2] = '\0\0'; /* To get this in the .data section */
  20. static char password[14] = '\0';
  21. static char nums[65] = /* remember the terminating null */
  22.         "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  23.  
  24. void
  25. motd() {
  26.     (void) fputs(msg, stdout);
  27. }
  28.  
  29. static void
  30. newmotd() {
  31.     register char *m, *line;
  32. #define    lim    70
  33.     printf("\nLimit lines to %d bytes.  End with a null line.\n",lim);
  34.     m = msg;
  35.     line = malloc(lim+2);
  36.     do {
  37.         fgets(line,lim+2,stdin);
  38.         if (strlen(line) == lim+1 && *(line+lim) != '\n') {
  39.             while (getchar() != '\n') ;
  40.             puts("\nLine too long, retype:");
  41.         } else {
  42.             if (*line == '\n') break;
  43.             strcpy(m,line);
  44.             m += strlen(line);
  45.             *m = '\0';
  46.             if (m - msg + 71 > MLEN) {
  47.                 puts("\nNot enough room for another line.  Ending here.\n");
  48.                 *line = '\n';
  49.             }
  50.         }
  51.     } while (*line != '\n');
  52.     free(line);
  53. }
  54.  
  55. static int
  56. wizard() {
  57.     auto long now;
  58.     auto struct tm *local;
  59.  
  60.     if (!yes(227,0,228)) return FALSE;
  61.     if (password[0] != '\0') {
  62.         puts("\nProve it!  Say the magic word!\n");
  63.         getin();
  64.         if (strcmp(crypt(word1,salt),password)) {
  65.             puts("\nFoo, you are nothing but a charlatan!\n");
  66.             return FALSE;
  67.         }
  68.     }
  69.     return TRUE;
  70. }
  71.  
  72. void
  73. maint(argv) char *argv;
  74. {
  75.     auto long now;
  76.  
  77.     if (!wizard()) return;
  78.     blklin = FALSE;
  79.     puts("\nNew magic word (null to leave it unchanged):");
  80.     getin();
  81.     now = time((long *)0);
  82.     *salt = nums[(now/64)%64];
  83.     *(salt+1) = nums[now%64];
  84.     strcpy(password,crypt(word1,salt));
  85.  
  86.     if (yes(229,0,0)) newmotd();
  87.  
  88.     puts("Okay.  Now being saved.\n");
  89.  
  90.     
  91.  
  92.     return;
  93. }
  94.